﻿using System;

using OST.Shared.Interfaces;
using OST.Shared.Extensions;

using mfLogger;

namespace OST.Anemometer
{
    public class AnemometerProvider : IAnemometerProvider
    {
        #region CTOR// Singleton
        //http://msdn.microsoft.com/en-us/library/ff650316.aspx
        //--> not thread-safe, with static initialization

        private static AnemometerProvider _instance = new AnemometerProvider();

        private AnemometerProvider()
        {
            AnemometerInstance = new ReedAnemometer();
            AnemometerInstance.Start();
            Logger.Debug("anemometer-provider instantiated and started");
        }

        public static AnemometerProvider Instance
        {
            get
            {
                return _instance;
            }
        }

        #endregion

        #region Properties

        /// <summary>
        /// wrapper-property 4 logging
        /// </summary>
        private ILoggerAppender Logger
        {
            get
            {
                return mfLogger.mfLogger.Instance;
            }
        }

        #endregion

        #region IAnemometerProvider
        public IAnemometer AnemometerInstance
        {
            get;
            private set;
        }

        public bool HasInstance
        {
            get { return AnemometerInstance != null; }
        } 
        #endregion

        #region INotifyPropertyChanged

        /// <summary>
        /// notifies clients over changes in puplic properties
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnNotifyPropertyChanged(String propertyName, object newValue)
        {

            if (PropertyChanged != null && !propertyName.IsNullOrEmpty())
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName, newValue));
            }
        }

        #endregion
    }
}
